﻿using System;
using System.Drawing;

namespace Oscilloscope.ChannelBuffer
{
	// Token: 0x02000028 RID: 40
	internal class SingleDigitalChannelBufferDataIterator : IChannelBufferDataIterator
	{
		// Token: 0x06000131 RID: 305 RVA: 0x00009784 File Offset: 0x00007984
		public void Initialize(ChannelBufferData[] dataBuffer, int dataBufferValidCount, double dataBufferStartTime, double timeInterval, int bitIndex)
		{
			this.iteratorCurrentIndex = 0;
			this.iteratorCurrentTime = dataBufferStartTime;
			this.iteratorTimeInterval = timeInterval;
			this.dataBufferValidCount = dataBufferValidCount;
			this.dataBuffer = dataBuffer;
			this.preValidData = -1.0;
			this.hasPreValidData = false;
			this.hasDataPadding = false;
		}

		// Token: 0x06000132 RID: 306 RVA: 0x000097D4 File Offset: 0x000079D4
		public bool Next(ref double value, ref double time)
		{
			while (this.iteratorCurrentIndex < this.dataBufferValidCount)
			{
				if (this.dataBuffer[this.iteratorCurrentIndex].IsValid)
				{
					if (!this.hasPreValidData)
					{
						value = this.dataBuffer[this.iteratorCurrentIndex].Data;
						time = this.iteratorCurrentTime;
						this.preValidData = this.dataBuffer[this.iteratorCurrentIndex].Data;
						this.hasPreValidData = true;
						this.hasDataPadding = false;
						this.iteratorCurrentIndex++;
						this.iteratorCurrentTime += this.iteratorTimeInterval;
						return true;
					}
					if (this.dataBuffer[this.iteratorCurrentIndex].Data != this.preValidData)
					{
						if (this.hasDataPadding)
						{
							value = this.dataBuffer[this.iteratorCurrentIndex].Data;
							time = this.iteratorCurrentTime;
							this.preValidData = this.dataBuffer[this.iteratorCurrentIndex].Data;
							this.hasDataPadding = false;
							this.iteratorCurrentIndex++;
							this.iteratorCurrentTime += this.iteratorTimeInterval;
							return true;
						}
						value = this.preValidData;
						time = this.iteratorCurrentTime;
						this.hasDataPadding = true;
						return true;
					}
					else if (this.iteratorCurrentIndex == this.dataBufferValidCount - 1)
					{
						value = this.preValidData;
						time = this.iteratorCurrentTime;
						this.iteratorCurrentIndex++;
						this.iteratorCurrentTime += this.iteratorTimeInterval;
						return true;
					}
				}
				this.iteratorCurrentIndex++;
				this.iteratorCurrentTime += this.iteratorTimeInterval;
			}
			return false;
		}

		// Token: 0x06000133 RID: 307 RVA: 0x00009994 File Offset: 0x00007B94
		public bool PeekNext(ref double value, ref double time)
		{
			double num = this.iteratorCurrentTime;
			for (int i = this.iteratorCurrentIndex; i < this.dataBufferValidCount; i++)
			{
				if (this.dataBuffer[i].IsValid)
				{
					if (!this.hasPreValidData)
					{
						value = this.dataBuffer[i].Data;
						time = num;
						return true;
					}
					if (this.dataBuffer[i].Data != this.preValidData)
					{
						if (this.hasDataPadding)
						{
							value = this.dataBuffer[i].Data;
							time = num;
							return true;
						}
						value = this.preValidData;
						time = num;
						return true;
					}
					else if (i == this.dataBufferValidCount - 1)
					{
						value = this.preValidData;
						time = num;
						return true;
					}
				}
				num += this.iteratorTimeInterval;
			}
			return false;
		}

		// Token: 0x06000134 RID: 308 RVA: 0x00009A60 File Offset: 0x00007C60
		public PointF[] SetNewPoint(float x, float y)
		{
			return new PointF[]
			{
				new PointF(x, y)
			};
		}

		// Token: 0x06000135 RID: 309 RVA: 0x00009A88 File Offset: 0x00007C88
		public PointF[] GetPoint()
		{
			return null;
		}

		// Token: 0x04000092 RID: 146
		private int iteratorCurrentIndex;

		// Token: 0x04000093 RID: 147
		private double iteratorCurrentTime;

		// Token: 0x04000094 RID: 148
		private double iteratorTimeInterval;

		// Token: 0x04000095 RID: 149
		private int dataBufferValidCount;

		// Token: 0x04000096 RID: 150
		private ChannelBufferData[] dataBuffer;

		// Token: 0x04000097 RID: 151
		private double preValidData;

		// Token: 0x04000098 RID: 152
		private bool hasPreValidData;

		// Token: 0x04000099 RID: 153
		private bool hasDataPadding;
	}
}
